package com.dylan.springcloud.ribbonloadbalancer.controller;

import com.dylan.springcloud.common.util.LogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Created by Dylan on 2018/10/13.
 */
@RestController
public class TestController {

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/add")
    public String add(Integer a, Integer b) {
        LogUtil.info("开始发送请求");
        String result = restTemplate.getForObject("http://client-a/add?a=" + a + "&b=" + b, String.class);
        LogUtil.info(result);
        return result;
    }

    @RequestMapping("/sub")
    public String sub(Integer a, Integer b) {
        LogUtil.info("开始发送请求");
        String result = restTemplate.getForObject("http://client-b/sub?a=" + a + "&b=" + b, String.class);
        LogUtil.info(result);
        return result;
    }

}
